package com.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dao.CaseDao;
import com.pojo.CasePojo;
import com.util.JsonUtil;
import com.util.Log;

@WebServlet(urlPatterns={"/admin/LoadAllCaseTitle"})
public class LoadAllCaseTitle extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		CaseDao dao = new CaseDao();
		String sWhere = " where 1=1 ";

		List<CasePojo> list = dao.loadCase(1, 5000, sWhere);
		
		String sList = "{";
		sList += "\"total\":" + dao.tabCount + ", \"rows\":";
		sList += JsonUtil.ListToJSON(list);
		sList += "}";
		dao.closeAll();
		Log.write(sList);

		response.setContentType("text/plain");
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();

		out.println(sList);
		out.flush();
		out.close();
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
